package com.bysj.lms.service.impl;

import com.bysj.lms.pojo.entity.Cabinetinfo;
import com.bysj.lms.mapper.CabinetinfoMapper;
import com.bysj.lms.pojo.vo.CabinetinfoVo;
import com.bysj.lms.service.ICabinetinfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bysj.lms.utils.StringUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaojiakai
 * @since 2022-02-04
 */
@Service
public class CabinetinfoServiceImpl extends ServiceImpl<CabinetinfoMapper, Cabinetinfo> implements ICabinetinfoService {

    @Autowired
    CabinetinfoMapper cabinetinfoMapper;

    @Override
    public PageInfo getList(Integer page, Integer count, String status) {
        PageHelper.startPage(page,count);
        List<CabinetinfoVo> list = cabinetinfoMapper.getList(status);
        return new PageInfo(list);
    }

    @Override
    public boolean adds(String roomId, String ecNumber, Integer row, Integer col) {

        ArrayList<Cabinetinfo> cabinetinfos = new ArrayList<>();
        for(int i=1;i<=row;i++){
            Cabinetinfo cabinetinfo = new Cabinetinfo();
            cabinetinfo.setRoomId(roomId);
            cabinetinfo.setEcNumber(ecNumber);
            cabinetinfo.setRow(i);
            for(int j=1;j<=col;j++){
                cabinetinfo.setCol(j);
            }
            cabinetinfo.setStatus("0");
            cabinetinfos.add(cabinetinfo);
        }
        int adds = cabinetinfoMapper.adds(cabinetinfos);
        return adds>0?true:false;
    }
}
